# -*- coding: utf-8 -*-

import kdurus
from kbasic import *
from ktest import *
from ksearch import *

import time
from durus.file_storage import FileStorage
from durus.connection import Connection
from durus.persistent_dict import PersistentDict

con=Connection(FileStorage("./test.fs"))
con.root['basis'] = B
S=SemanticDB(DictSimilarity())
S.Add(knowledge_database)
con.root['sdb'] = S
v1 = Variable(B, 'v1', int_system)
v2 = Variable(B, 'v2', int_system)
mask = KRelation(be_friends, [v1,v2])

N = 10000

t1 = t = time.time()
for i in xrange(0,N):
    X = S.Search(mask)
print '\n'.join(map(str, S.Search(mask)))
print "Time:",time.time()-t
con.commit()
con.storage.close()

del con;
del B;
del S;
del v1;
del v2;
del mask;

con=Connection(FileStorage("./test.fs"))
B=con.root['basis']
S=con.root['sdb']
v1 = B.Variables['v1']
v2 = B.Variables['v2']
be_friends = B.Universum['друзья']
mask = KRelation(be_friends, [v1,v2])

t1 = t = time.time()
for i in xrange(0,N):
    X = S.Search(mask)
print '\n'.join(map(str, S.Search(mask)))
print "Time:",time.time()-t

